package com.erp.servlet;

import com.erp.bean.Commodity;
import com.erp.bean.Emp;
import com.erp.bean.Entrepot;
import com.erp.bean.Inventory;
import com.erp.service.CommodityService;
import com.erp.service.EntrepotService;
import com.erp.service.InventoryService;
import com.erp.service.impl.CommodityServiceImpl;
import com.erp.service.impl.EntrepotServiceImpl;
import com.erp.service.impl.InventoryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @author lyb
 * 创建分仓显示控制器
 */
@WebServlet("/inventorypart.action")
public class InventoryListPartServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取用户请求id
        String entid=req.getParameter("entid");
        //类型转化
        int ent=Integer.valueOf(entid);
        String gid=req.getParameter("gid");
        int egid=Integer.valueOf(gid);
       EntrepotService entrepotService=new EntrepotServiceImpl();
        Entrepot entrepot=entrepotService.findByentid(ent);
        //将仓库对象存入作用域
        req.setAttribute("entrepot",entrepot);
        //创建商品业务逻辑对象
        CommodityService commodityService=new CommodityServiceImpl();
        Commodity commodity=commodityService.findByGId(egid);
        req.setAttribute("commodity",commodity);
        //获取session对象
        HttpSession session=req.getSession();
        Object obj=session.getAttribute("currentUser");
        Emp enp=(Emp)obj;
        req.setAttribute("enp",enp);
        req.getRequestDispatcher("addinventory.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
